package cn.fintecher.pangolin.service.dataimp.repository;

import cn.fintecher.pangolin.common.enums.BaseStatus;
import cn.fintecher.pangolin.entity.mysql.Principal;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Auther: xiaqun
 * @Description:
 * @Date: 11:01 2019/8/27
 */
public interface PrincipalRepository extends JpaRepository<Principal, String>, QuerydslPredicateExecutor<Principal> {
    /**
     * 查询序列号
     */
    @Query(value = "SELECT next_seq('batchSeq',3) from DUAL", nativeQuery = true)
    Object getBatchNumber();

    /**
     * 重置序列号
     */
    @Transactional
    @Modifying
    @Query(value = "update batch_seq set current_seq = 0 where seq_name = 'batchSeq'", nativeQuery = true)
    int reset();

    /**
     * 根据名称查询委托方
     */
    Principal findByName(String name);

    /**
     * 获取委托方集合
     */
    List<Principal> findAllByStatus(BaseStatus status);
}
